<?php require_once('Connections/cnn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

mysql_select_db($database_cnn, $cnn);
$query_categorias = "SELECT * FROM categorias";
$categorias = mysql_query($query_categorias, $cnn) or die(mysql_error());
$row_categorias = mysql_fetch_assoc($categorias);
$totalRows_categorias = mysql_num_rows($categorias);

$maxRows_productos = 4;
$pageNum_productos = 0;
if (isset($_GET['pageNum_productos'])) {
  $pageNum_productos = $_GET['pageNum_productos'];
}
$startRow_productos = $pageNum_productos * $maxRows_productos;

mysql_select_db($database_cnn, $cnn);
$query_productos = "SELECT * FROM productos";
$query_limit_productos = sprintf("%s LIMIT %d, %d", $query_productos, $startRow_productos, $maxRows_productos);
$productos = mysql_query($query_limit_productos, $cnn) or die(mysql_error());
$row_productos = mysql_fetch_assoc($productos);

if (isset($_GET['totalRows_productos'])) {
  $totalRows_productos = $_GET['totalRows_productos'];
} else {
  $all_productos = mysql_query($query_productos);
  $totalRows_productos = mysql_num_rows($all_productos);
}
$totalPages_productos = ceil($totalRows_productos/$maxRows_productos)-1;

$queryString_productos = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_productos") == false && 
        stristr($param, "totalRows_productos") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_productos = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_productos = sprintf("&totalRows_productos=%d%s", $totalRows_productos, $queryString_productos);

if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
  
  $logoutGoTo = "Productos.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "Admin,User,Client";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "error.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
$colname_usuarios = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_usuarios = $_SESSION['MM_Username'];
}
mysql_select_db($database_cnn, $cnn);
$query_usuarios = sprintf("SELECT * FROM usuario WHERE Email = %s", GetSQLValueString($colname_usuarios, "text"));
$usuarios = mysql_query($query_usuarios, $cnn) or die(mysql_error());
$row_usuarios = mysql_fetch_assoc($usuarios);
$totalRows_usuarios = mysql_num_rows($usuarios);
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/plantilla.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ventas</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="css/estilo.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/component.css" />
    <link type="text/css" href="css/zoomy.css" rel="stylesheet">
    <link rel="stylesheet" href="css/jquery-ui.css" />
        <link rel="stylesheet" href="css/style.css" />
          <link href="css/styles.css" type="text/css" media="all" rel="stylesheet" />
          <link href="css/menu3.css" rel="stylesheet" type="text/css">


  


<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- InstanceBeginEditable name="1" -->
<!-- Skitter JS -->
  <script type="text/javascript" language="javascript" src="js/jquery-1.6.3.min.js"></script>
  <script type="text/javascript" language="javascript" src="js/menu.js"></script>
    <script src="js/modernizr.custom.js"></script>
    <script src="JSLogin/login.js"></script>
    
     <script src="JSLogin/jquery-ui.js"></script>

<script type="text/javascript" src="js/zoomy.min.js"></script>

<script type="text/javascript">
$(function () {
    $('.zoom').zoomy();
});
</script>


<![endif]-->


<!-- InstanceEndEditable -->

</head>


<body> 


<div class="container">
  <header>
    <img src="images/banner.png" width="960" height="194" />

      <ul class="menu3">
    <li> <a href="#">Bienvenido/@: <?php echo $row_usuarios['Usuario']; ?></a>
 
        <ul>
          <?php if($_SESSION['MM_UserGroup']=='Admin'){ ?>


            <li><a href="admin/index2.php" class="ele">Administracion del sitio</a></li> <?php } ?>
            <li><a href="<?php echo $logoutAction ?>" class="auvi">Cerrar Sesion</a></li>
        </ul>
    </li>
    
</ul>
  </header>
   <ul class="menu">
            <li><a href="index_r.php">Home</a></li>
            <li><a href="Productos_r.php">Productos</a></li>
            <li><a href="#">Acerca</a></li>
            <li><a href="Contactenos_r.php">Contactanos</a></li>
        </ul>
 
   <br><br><br><br><br><br>
 <nav class="dr-menu">
            <div class="dr-trigger"><span class="dr-icon dr-icon-menu"></span><a class="dr-label">Categorias</a></div>
            <ul>
   <?php
            $con=mysql_query("select IdCategoria from categorias");
            while ($row=mysql_fetch_assoc($con)){
              for ($i = $row['IdCategoria']; $i <= $row['IdCategoria']; $i++){
              $consulta= mysql_query("select strNombre from categorias where IdCategoria = '$i'");
              $datos = mysql_fetch_assoc($consulta);
              $Nombre= $datos['strNombre'];?>

                  <li><a class="dr-icon dr-icon-instagram" href="Productos1_r.php?IdCategoria=<?php echo $i; ?>"><?php echo "$Nombre"; ?></a></li>
                      
                  <?php
              $i++;
              }
            }?>
  </ul>
          </nav>


          <section>
        <form id="form1" method="post" autocomplete="off">
          
          <ul>
   <?php
            $con=mysql_query("select IdSucursal from sucursales");
            while ($row=mysql_fetch_assoc($con)){
              for ($i = $row['IdSucursal']; $i <= $row['IdSucursal']; $i++){
              $consulta= mysql_query("select Nombre from sucursales where IdSucursal = '$i'");
              $datos = mysql_fetch_assoc($consulta);
              $Nombre= $datos['Nombre'];?>

                   <li><input id="checkbox" name="checkbox[]" type="checkbox" onClick="location.href='Productos2_r.php?IdSucursal=<?php echo $i; ?>'"><label for="cb<?php echo $i; ?>" onClick="Productos2.php?IdSucursal=<?php echo $i; ?>"><?php echo "$Nombre"; ?></label></li>  
                    
                  <?php
              $i++;
              }
            }?>
       
   </ul> 
    </form>
      </section>


        

  <!-- InstanceBeginEditable name="2" --> 
 
  <div id="contenido">
  

  </div>
  <script type="text/javascript">
            $(document).ready(function() {
                $('.menu').tagdrop({tagPaddingTop: '60px',bgColor: '#B1CCED',bgMoverColor: '#7FB0F0',textColor: '#e0e0e0'});
            });
        </script>

   <table width="29%" align="right">
    <tr>
         
          <td><table >
            <tr>
              <?php
$productos_endRow = 0;
$productos_columns = 2; // number of columns
$productos_hloopRow1 = 0; // first row flag
do {
    if($productos_endRow == 0  && $productos_hloopRow1++ != 0) echo "<tr>";
   ?>
              <td><table width="64%" height="325" border="5" align="center" id="sidebar3">
                <tr>
                  <td ><a href="images/productos/<?php echo $row_productos['Imagen']; ?>" class="zoom"><img src="images/productos/<?php echo $row_productos['Imagen']; ?>" width="203" height="198"></a><br/></td>
                </tr>
                
                <tr>
           <td bgcolor="#00CCFF"><p>Nombre: <?php echo $row_productos['strNombre']; ?></p></td>
                </tr>
                <tr>
                  <td height="27" bgcolor="#00CCFF"><p>Descripción: <?php echo $row_productos['strDescripcion']; ?></p></td>
                </tr>
                <tr>
                  <td height="27" bgcolor="#00CCFF"><p>Marca: <?php echo $row_productos['Marca']; ?></p></td>
                </tr>
                <tr>
                  <td height="27" bgcolor="#00CCFF"><p>Precio: $<?php echo $row_productos['Precio']; ?></p></td>
                </tr>
                 <tr>
                  <td height="27" bgcolor="#00CCFF"><p>Categoria: <?php
            $con=mysql_query("select IdCategoria from categorias");
            while ($row=mysql_fetch_assoc($con)){
              for ($i = $row['IdCategoria']; $i <= $row['IdCategoria']; $i++){
              $consulta= mysql_query("select strNombre from categorias where IdCategoria = '$i'");
              $datos = mysql_fetch_assoc($consulta);
              $Nombre= $datos['strNombre'];
                  if ($row_productos['IdCategoria'] == $i) {
                    echo "$Nombre";   
                  }
              $i++;
              }
            }?></p></td>
                </tr>
                 <tr>
                  <td height="27" bgcolor="#00CCFF"><p>Sucursal: <?php
            $con=mysql_query("select IdSucursal from sucursales");
            while ($row=mysql_fetch_assoc($con)){
              for ($i = $row['IdSucursal']; $i <= $row['IdSucursal']; $i++){
              $consulta= mysql_query("select Nombre from sucursales where IdSucursal = '$i'");
              $datos = mysql_fetch_assoc($consulta);
              $Nombre= $datos['Nombre'];
                  if ($row_productos['IdSucursal'] == $i) {
                    echo "$Nombre";   
				  }
              $i++;             
              }
            }  ?></p>
</td>
                </tr>
              </table></td>
              <?php  $productos_endRow++;
if($productos_endRow >= $productos_columns) {
  ?>
            </tr>
            <?php
 $productos_endRow = 0;
  }
} while ($row_productos = mysql_fetch_assoc($productos));
if($productos_endRow != 0) {
while ($productos_endRow < $productos_columns) {
    echo("<td>&nbsp;</td>");
    $productos_endRow++;
}
echo("</tr>");
}?>
          </table></td>
      
    </tr>
  </table>
   <table border="0" id="numeros">
     <tr>
       <td><?php if ($pageNum_productos > 0) { // Show if not first page ?>
           <a href="<?php printf("%s?pageNum_productos=%d%s", $currentPage, 0, $queryString_productos); ?>">Primero</a>
           <?php } // Show if not first page ?></td>
       <td><?php if ($pageNum_productos > 0) { // Show if not first page ?>
           <a href="<?php printf("%s?pageNum_productos=%d%s", $currentPage, max(0, $pageNum_productos - 1), $queryString_productos); ?>">Anterior</a>
           <?php } // Show if not first page ?></td>
       <td><?php if ($pageNum_productos < $totalPages_productos) { // Show if not last page ?>
           <a href="<?php printf("%s?pageNum_productos=%d%s", $currentPage, min($totalPages_productos, $pageNum_productos + 1), $queryString_productos); ?>">Siguiente</a>
           <?php } // Show if not last page ?></td>
       <td><?php if ($pageNum_productos < $totalPages_productos) { // Show if not last page ?>
           <a href="<?php printf("%s?pageNum_productos=%d%s", $currentPage, $totalPages_productos, $queryString_productos); ?>">&Uacute;ltimo</a>
           <?php } // Show if not last page ?></td>
     </tr>
   </table>
  <!-- InstanceEndEditable -->
   

  <!-- script del menu -->
  
  
  
  <div class="content">
    

    
    <!-- end .content --></div>  

  <footer>
    <h3>Super Gangas</h3>
  </footer>
  <!-- end .container --></div>

</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($categorias);

mysql_free_result($productos);
?>
